<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="thx" uri="/thx-tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<div class="row">
	<div class="col-md-12">
		<div class="box">
			<div class="box-header with-border">
				<div class="row">
					<form action="${pageContext.request.contextPath}/mywork!list.action?entity.workState=noStart&isExpand=${expand}&appId=${appId}&entity.workType=${entity.workType}&officeDocTypeAppIds=${officeDocTypeAppIds}"
						 class="search-panel" name="search-form" result-container=".tab-content .active">
						<s:if test="entity.workState!='start'">
							<input type="text" name="entity.workTitle" value="${entity.workTitle}" class="form-control" placeholder="标题名">
							<button type="button" class="btn btn-primary search-btn">搜索</button>
						</s:if>
					</form>
				</div>
			</div>
			<div class="box-body no-padding">
				<div class="row">
					<div class="col-sm-12">
						<form name="listWork" id="workSearch" method="post">
							<input type="hidden" name="appId" id="workState" value="${appId}" />
							<input type="hidden" name="entity.workState" id="workState" value="${entity.workState}" />
							<input type="hidden" name="expand" id="expand" value="${expand }" />
							<input type="hidden" name="officeDocTypeAppIds" value="${officeDocTypeAppIds}" />
							<table class="table table-bordered">
					           	<tr>
									<s:if test="entity.workState!='start'">
										<th width="5%">
					                        <input type="checkbox" />
					                    </th>
					                    <s:if test="entity.workType!=null && entity.workType=='document'">
											<th>文件名称</th>
											<th>公文类型</th>
											<th>起草时间</th>
											<th>结束时间</th>
											<th>当前状态</th>
										</s:if>
										<s:else>
											<th>标题</th>
											<th>应用名称</th>
											<th>起草时间</th>
											<th>结束时间</th>
											<th>当前状态</th>
										</s:else>
									</s:if>
									<s:if test="entity.workState=='start'">
										<th width="5%">
					                        <input  type="checkbox" />
					                    </th>
					                    <s:if test="entity.workType!=null && entity.workType=='document'">
											<th>文件名称</th>
											<th>公文类型</th>
											<th>起草时间</th>
											<th>操作</th>
										</s:if>
										<s:else>
											<th>标题</th>
											<th>应用名称</th>
											<th>起草时间</th>
											<th>操作</th>
										</s:else>
									</s:if>
								</tr>
					            <s:if test="empty list">
					                <tr>
						             	<s:if test="entity.workState!='start'">
						                	<td colspan="6">暂无数据！</td>
						                </s:if>
						             	<s:if test="entity.workState=='start'">
						                	<td colspan="5">暂无数据！</td>
						                </s:if>
					               </tr>
					           	</s:if>
								<s:iterator value="list" var="view">
									<tr>
										<s:if test="entity.workState!='start'">
											<td>
												<input type="checkbox" name="delId" value="<s:property value='#view.workId'/>" />
											</td>
											<s:if test="#view.workTitle==null or #view.workTitle==''">
												<td>
													<a target="_blank"
														href="${pageContext.request.contextPath}/jbpmService/work/getWorkByWorkId?workId=<s:property value='#view.workId'/>">
														<span title="<s:property value='#view.appName'/>" style="width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; text-align: center;display: inline-block;"><s:property value='#view.appName'/></span>
													</a>
												</td>
											</s:if>
											<s:else>
												<td>
													<a target="_blank"
														href="${pageContext.request.contextPath}/jbpmService/work/getWorkByWorkId?workId=<s:property value='#view.workId'/>">
														<span title="<s:property value='#view.workTitle'/>" style="width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; text-align: center;display: inline-block;"><s:property value='#view.workTitle'/></span>
													</a>
												</td>
											</s:else>
											<td>${view.appName }</td>
											<td>
												<fmt:formatDate value="${view.startTime }" pattern="yyyy-MM-dd HH:mm:ss" />
											</td>
											<td>
												<fmt:formatDate value="${view.endTime }" pattern="yyyy-MM-dd HH:mm:ss" />
											</td>
											<td>
												<span title="${view.curActivityName}" style="width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; text-align: center;display: inline-block;">${view.curActivityName}</span>
											</td>
										</s:if>
										<s:if test="entity.workState=='start'">
											<td>
												<input type="checkbox" name="delId" value="<s:property value='#view.workId'/>" />
											</td>
											<s:if test="#view.workTitle==null or #view.workTitle==''">
												<td>
													<a target="_blank" href="${pageContext.request.contextPath}/jbpmService/work/getWorkByWorkId?workId=<s:property value='#view.workId'/>">
														<span title="<s:property value='#view.appName'/>" style="width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; text-align: center;display: inline-block;"><s:property value='#view.appName'/></span>
													</a>
												</td>
											</s:if>
											<s:else>
												<td>
													<a target="_blank" href="${pageContext.request.contextPath}/jbpmService/work/getWorkByWorkId?workId=<s:property value='#view.workId'/>">
														<span title="<s:property value='#view.workTitle'/>" style="width:150px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap; text-align: center;display: inline-block;"><s:property value='#view.workTitle'/></span>
													</a>
												</td>
											</s:else>
											<td>${view.appName }</td>
											<td>
												<fmt:formatDate value="${view.startTime }" pattern="yyyy-MM-dd HH:mm:ss" />
											</td>
											<td>
												<a class="icon icon-delete" title="删除草稿" onclick="javascript:delDatas('${view.workId}');">删除</a>
											</td>
										</s:if>
									</tr>
								</s:iterator>
							</table>
				        </form>
					</div>
				</div>
			</div>
			<div class="box-footer">
				<!--分页区-->
				<div class="pagePanel">
					<thx:pages pageNo="page.curPage" total="page.totalPage" theme="number">
						<s:param name="entity.workState" value="entity.workState"></s:param>
						<s:param name="entity.workType" value="entity.workType"></s:param>
						<s:param name="isExpand" value="isExpand"></s:param>
						<s:param name="appId" value="appId"></s:param>
						<s:param name="officeDocTypeAppIds" value="officeDocTypeAppIds"></s:param>
					</thx:pages>
				</div>
			</div>
		</div>
	</div>
</div>				
<script type="text/javascript">
	$( function() {
		list.init();
		page.init(".tab-content .active");
	});
	
	function delDatas(workId){
		$.jConfirm('提示','确定要删除吗？',function(r){
			if(r){
				$.ajax({
		            type : "POST",
					url : "../jbpmService/deleteWork",
					data: "workId="+workId,															
					success : function(msg){	
						if(msg == "删除成功！"){
							window.location.href=window.location.href;
						}else{
							alert(msg);
						}
					}
			     });
			}
		})	
	}
	function delWorks(){
	    var flag = false;
  			var de = document.getElementsByName("delId");
  			for(i = 0; i < de.length; i++){
      			if(de[i].checked == true){
          			flag = true;
          			break;
      			} 
   		}		
   		if(flag == false){
   		      $.jAlert('提示',"至少选择一个待删除记录",'info');
     			  return false;
 			}
 			
		$.jConfirm("确定对话框","代办中如果有相关信息将一并删除,确定要删除吗?", function(r){
			if (r){
				 document.listWork.action="mywork!deldraftWorks.action" ;
                 document.listWork.submit(); 
		    }
		});
	}
</script>		

